﻿package com.tudou.home.newskin.buttons
{
    import com.tudou.skin.*;
    import com.tudou.skin.common.bar.*;
    import flash.display.*;

    public class BrightnessBar extends BrightnessBackgroundMC implements IBar
    {
        private var bar:DisplayObject;
        private const END_Y:int = -68;
        private const START_Y:int = -7;
        private var drag:DisplayObject;
        protected var $barData:Object;

        public function BrightnessBar()
        {
            $barData = {};
            bar = new BrightnessBarMC();
            bar.x = 11;
            bar.y = START_Y;
            drag = new BrightnessDragerBTN();
            drag.x = int(this.width / 2);
            drag.y = bar.y;
            addChild(bar);
            addChild(drag);
            var _loc_1:Boolean = true;
            this.buttonMode = true;
            this.useHandCursor = _loc_1;
            BarUtil.actMouse(this, false, lineFun);
            setValue(0.5);
            return;
        }// end function

        public function getSkin() : InteractiveObject
        {
            return this;
        }// end function

        public function isDragging() : Boolean
        {
            return $barData.isDragging;
        }// end function

        private function inverseLineFun(param1:Number) : Number
        {
            return (param1 + 1) / 2;
        }// end function

        public function getMin() : Number
        {
            return 0;
        }// end function

        public function get barData() : Object
        {
            return $barData;
        }// end function

        public function getActMin() : Number
        {
            return START_Y;
        }// end function

        private function lineFun(param1:Number) : Number
        {
            var _loc_2:* = 2 * param1 - 1;
            if (_loc_2 >= -0.15 && _loc_2 <= 0.15)
            {
                _loc_2 = 0;
            }
            return _loc_2;
        }// end function

        public function getMax() : Number
        {
            return -this.height;
        }// end function

        public function getActMax() : Number
        {
            return END_Y;
        }// end function

        public function setValue(param1:Number) : void
        {
            if (param1 <= -1)
            {
                param1 = -1;
            }
            if (param1 >= 1)
            {
                param1 = 1;
            }
            var _loc_2:* = inverseLineFun(param1);
            drag.y = _loc_2 * (getActMax() - getActMin()) + getActMin();
            bar.height = bar.y - drag.y;
            return;
        }// end function

        public function set barData(param1:Object) : void
        {
            $barData = param1;
            return;
        }// end function

        public function getValue() : Number
        {
            var _loc_1:* = (drag.y - getActMin()) / (getActMax() - getActMin());
            var _loc_2:* = lineFun(_loc_1);
            return _loc_2;
        }// end function

    }
}
